<template>
  <div style="background-color: #FFFFFF; width: 100%; height: 1000px; padding: 15px;">
    <div style="margin-left: 26px; font-size: 13px; font-weight: bold;">
      <span>打包机历史数据查询</span>
    </div>
    <div style="margin-left: 20px;margin-top: 20px; padding:5px">
      <a-row :gutter="16">
        <a-col :span="3">
          <a-select
            placeholder="选择车间"
            style="width: 100%"
            v-model="workshop"
            @change="handleChangeWorkshop"
          >
            <a-select-option value="jack">
              立华
            </a-select-option>
          </a-select>
        </a-col>
        <a-col :span="4" v-if="checkPageFlag">
          <a-select
            placeholder="选择温湿度表"
            style="width: 100%"
            v-model="tAH"
            @change="handleChangeTAH"
          >
            <a-select-option value="jack">
              立华
            </a-select-option>
          </a-select>
        </a-col>


        <a-col :span="5" >
          <div >
            <a-range-picker v-model="riqi"
                            :show-time="{ format: 'HH:mm' }"
                            format="YYYY-MM-DD HH:mm"
                            :placeholder="['开始时间', '结束时间']"
                            @change="onChange"
                            @ok="onOk"
                            style="width: 100%"
            />
          </div>
        </a-col>

        <a-col :span="2">
          <div >
            <a-button @click="onSearch()" type="primary">
              查询
            </a-button>
          </div>
        </a-col>

        <div style="float: right">
          <a-button @click="checkPageFlag=false" type="primary">
            温湿度变化曲线
          </a-button>
        </div>

        <div style="float: right; margin-right: 1%;">
          <a-button @click="checkPageFlag=true" type="primary">
            温湿度历史数据
          </a-button>
        </div>

      </a-row>

      <div style="margin-top: 30px;" v-if="checkPageFlag">
        <a-table :columns="columns" :data-source="data">
          <a slot="name" slot-scope="text,record">{{ text }}</a>
        </a-table>
      </div>

      <div v-if="!checkPageFlag" style="display: flex;margin-top: 20px;width: 100%" >
        <div style="width: 35%" >
          <a-table :columns="columns" :data-source="data" :pagination="false">
            <span slot="temperature" slot-scope="text" style="color: rgb(35, 184, 153)">{{ text }}</span>
            <span slot="humidity" slot-scope="text" style="color: rgb(56, 125, 255)">{{ text }}</span>
          </a-table>
        </div>
        <div style="width: 65%;" >
          <div id="main" style="height: 400px;width: 90%"></div>
        </div>
      </div>

    </div>
  </div>

</template>
<script>

import * as echarts from 'echarts'

const columns = [
  {
    title: '温湿度表',
    dataIndex: 'tAH',
    key: 'tAH',
    ellipsis: true,
  },
  {
    title: '时间',
    dataIndex: 'Time',
    key: 'Time',
    ellipsis: true,
  },
  {
    title: '温度',
    dataIndex: 'temperature',
    key: 'temperature',
    ellipsis: true,
  },
  {
    title: '湿度',
    dataIndex: 'humidity',
    key: 'humidity',
    ellipsis: true,
  },

];

const data = [
  {
    key: '1',
    tAH: '01',
    Time: 3212313123,
    temperature: '五房',
    humidity:'',
  },

];


export default {
  data() {
    return {
      checkPageFlag:true,
      workshop:undefined,
      tAH:undefined,
      riqi:undefined,
      data: [{
        key: '1',
        column1: '1#空调室新风',
        column2: 16.3,
        column3: '75.8%',
      }],
      columns,
      options: [{
        label: '一纺',
        value: '1'
      }, {
        label: '二纺',
        value: '2'
      }, {
        label: '三纺',
        value: '3'
      }]

    };
  },

  mounted() {
    if (!this.checkPageFlag) {
      this.getEchartsData()
    }
  },
  methods: {
    onSearch(){

    },

    // edit(item){
    //
    // },
    handleChangeWorkshop(value) {
      console.log(`selected ${value}`);
    },
    handleChangeTAH(value) {
      console.log(`selected ${value}`);
    },
    onChange(value, dateString) {
      console.log('Selected Time: ', value);
      console.log('Formatted Selected Time: ', dateString);
    },
    onOk(value) {
      console.log('onOk: ', value);
    },
    getEchartsData() {
      var myChart = echarts.init(document.getElementById('main'))
      let option = {
        tooltip: {
          trigger: 'axis',
        },
        legend: {
          data: ['温度', '湿度'],
          right: 30
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: {
          type: 'category',
          boundaryGap: false,
          data: ['00:00', '02:00', '04:00', '06:00', '08:00', '10:00', '12:00', '14:00', '16:00', '18:00']
        },
        yAxis: [
          {
            type: 'value',
            axisLabel: {
              formatter: '{value} °C'
            }
          },
          {
            type: 'value',
            min: 0,
            max: 100,
            position: 'right',
            axisLabel: {
              formatter: '{value} %'
            }
          }],
        series: [
          {
            name: '温度',
            type: 'line',
            stack: 'Total',
            data: [120, 132, 101, 134, 90, 230, 210, 210, 210, 210]
          },
          {
            name: '湿度',
            type: 'line',
            stack: 'Total',
            data: [220, 182, 191, 234, 290, 330, 310, 210, 210, 210]
          },
        ]
      }
      myChart.setOption(option)
    },
  },
};
</script>
<style lang="less" scoped>
//#main {
//  width: 70%;
//  height: 400px;
//  margin-left:10px;
//}
</style>